<?php
/**
 * Stylet Classifield - PHP Template Engine
 *
 * @category     Stylet
 * @package      DOM
 * @author       Jano Chen <janochen@gmail.com>
 * @copyright    Copyright (c) 2008-2009 Jano Chen (http://jano.tw)
 * @link         http://code.google.com/p/classifield/
 * @license      http://code.google.com/p/classifield/source/browse/LICENSE.txt  New BSD License
 * @link         $HeadURL$
 * @version      $Revision$
 * @modifiedby   $LastChangedBy$
 * @lastmodified $Date$
 */
class DomNodeIterator extends DOMNode implements Iterator {
  public $firstNode;
  public $currentNode;

  public function __construct(DOMNode $node) {
    $this->firstNode = $node;
    $this->currentNode = $node;
  }

  /* implements Iterator */
  function current() {
    return $this->currentNode;
  }
  function key () {
    return $this->currentNode;
  }
  function next () {
    $this->currentNode = $this->currentNode->nextSibling;
  }
  function rewind () {
    $this->currentNode = $this->firstNode;
  }
  function valid () {
    if ($this->currentNode instanceof DOMNode) {
      return true;
    }
    return false;
  }
}